const path = require('path');
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');

/**
 * 尽量减小搜索范围
 * target: '_dll_[name]' 指定导出变量名字
 */

const stableLibs = [
  'fastclick',
  'react',
  'react-dom',
  'react-redux',
  'react-router',
  'react-router-dom',
  'redux',
  'redux-saga',
  'immutable',
  'md5',
  'dva',
  'dva-loading',
];

const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';

module.exports = {
  mode,
  entry: {
    vendor: stableLibs,
  },
  output: {
    path: path.join(__dirname, '../lib'),
    filename: `[name].dll.${mode}.js`,
    library: '_dll_[name]', // 全局变量名，其他模块会从此变量上获取里面模块
  },
  // manifest是描述文件
  plugins: [
    new CompressionPlugin(),
    new webpack.DllPlugin({
      name: '_dll_[name]',
      path: path.join(__dirname, `../lib/manifest.${mode}.json`),
    }),
  ],
};
